import java.util.Iterator;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

import friendShips.User;



@Path("/logout/{username}")
public class Logout {
@GET
@Produces("text/html")
public String getOut(@PathParam("username") String userName )
{
	SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); 
	Session session = sessionFactory.openSession();
	UserManager manager = new UserManager(session); 
	Query query = session.createQuery("from User user where user.email = :newEmail");
	query.setParameter("newEmail", userName);
	
	List <User>list = query.list();
	Iterator<User> it=list.iterator();
	User tempUser= new User();
	tempUser=it.next();
	
	tempUser.setOnline(false);
	manager.updateUser(tempUser);
	session.flush();
	return "GOOD";
	
}
	
}
